//
//  SelfInfoImageTableViewCell.m
//  customer
//
//  Created by Holothurian on 2018/10/24.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "SelfInfoImageTableViewCell.h"

@implementation SelfInfoImageTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = Font28;
        _nameLabel.textColor = [HSPublic colorWithHexString:@"666666"];
        [self.contentView addSubview:_nameLabel];
        AutoWeakSelf
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView).offset(15);
            make.centerY.equalTo(weakSelf.contentView);
            make.size.mas_equalTo(CGSizeMake(70,30));
        }];
        
        _headImgView = [[UIImageView alloc]init];
        _headImgView.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:_headImgView];
        _headImgView.userInteractionEnabled = YES;
        [_headImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.contentView).offset(-10);
            make.centerY.equalTo(weakSelf.contentView);
            make.size.mas_equalTo(CGSizeMake(50, 50));
        }];
        _headImgView.layer.cornerRadius = 25;
        _headImgView.layer.masksToBounds = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
        [_headImgView addGestureRecognizer:tap];
    }
    return self;
}

- (void)cellForLayout:(NSDictionary *)dict{
    NSString *name = [dict objectForKey:@"key"];
    NSString *urlStr = [dict objectForKey:@"value"];
    self.nameLabel.text = name;
    if (![urlStr containsString:@"http"]) {
        [self.headImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kCustomerImageIP,urlStr]] placeholderImage:[UIImage imageNamed:@"selfCenter_HeaderImg"]];
    }else{
        [self.headImgView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"selfCenter_HeaderImg"]];
    }
}

- (void)tapAction{
    if ([self.delegate respondsToSelector:@selector(infoImageTableCellTapAction)]) {
        [self.delegate infoImageTableCellTapAction];
    }
}

@end
